<template>
  <div class="chart-container">
    <a-tree
      v-model="checkedKeys"
      checkable
      :expanded-keys="expandedKeys"
      :auto-expand-parent="autoExpandParent"
      :selected-keys="selectedKeys"
      :tree-data="treeData"
      @expand="onExpand"
      @select="onSelect"
      :replaceFields="replaceFields"
    />
  </div>
</template>

<script>
// const treeData = [
//   {
//     title: "00",
//     key: "0-0",
//     children: [
//       {
//         title: "000",
//         key: "0-0-0",
//         children: [
//           { title: "0000", key: "0-0-0-0" },
//           { title: "0001", key: "0-0-0-1" },
//           { title: "0002", key: "0-0-0-2" }
//         ]
//       },
//       {
//         title: "0-0-1",
//         key: "0-0-1",
//         children: [
//           { title: "0-0-1-0", key: "0-0-1-0" },
//           { title: "0-0-1-1", key: "0-0-1-1" },
//           { title: "0-0-1-2", key: "0-0-1-2" }
//         ]
//       },
//       {
//         title: "0-0-2",
//         key: "0-0-2"
//       }
//     ]
//   },
//   {
//     title: "0-1",
//     key: "0-1",
//     children: [
//       { title: "0-1-0-0", key: "0-1-0-0" },
//       { title: "0-1-0-1", key: "0-1-0-1" },
//       { title: "0-1-0-2", key: "0-1-0-2" }
//     ]
//   },
//   {
//     title: "0-2",
//     key: "0-2"
//   }
// ];

export default {
  name: "demoTwenty15",
  filters: {},
  data() {
    return {
      quanxianData:[],
      expandedKeys: [],
      autoExpandParent: true,
      checkedKeys: [],
      selectedKeys: [],
      treeData: [],
      replaceFields: {
        children: "personTreeList",
        title: "organizationName",
        key: "organizationId"
      }
    };
  },
  watch: {
    checkedKeys(val) {
      console.log("onCheck aaaaaaa", val);
    }
  },
  components: {},
  created() {
    let dataData = {
      code: 200,
      msg: "处理成功",
      time: 1638934287103,
      success: true,
      data: [
        {
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          current: null,
          size: null,
          keyword: null,
          organizationId: "1449934175342755842",
          organizationName: "研发部门-A",
          parentOrganizationId: "1449933525389213697",
          allId: "1449933525389213697,1449934175342755842",
          mainDataId: "10002",
          officeAreaId: "1443123133698580481",
          deleted: null,
          remark: null,
          personTreeList: [
            {
              createBy: null,
              createTime: null,
              updateBy: null,
              updateTime: null,
              current: null,
              size: null,
              keyword: null,
              personId: "1446295763134050306",
              personName: "刘成",
              sex: "1",
              orgnizationId: null,
              areaId: null,
              officeName: "邮电大厦",
              personCatId: "1",
              staffCode: "A1001",
              managerId: "MP004",
              mobileNo: "18856889966",
              hasFace: null
            },
            {
              createBy: null,
              createTime: null,
              updateBy: null,
              updateTime: null,
              current: null,
              size: null,
              keyword: null,
              personId: "1446295886547251201",
              personName: "王晨",
              sex: "1",
              orgnizationId: null,
              areaId: null,
              officeName: "邮电大厦",
              personCatId: "1",
              staffCode: "A1002",
              managerId: "MP004",
              mobileNo: "18888889999",
              hasFace: null
            },
            {
              createBy: null,
              createTime: null,
              updateBy: null,
              updateTime: null,
              current: null,
              size: null,
              keyword: null,
              personId: "1451363428911316993",
              personName: "李四",
              sex: "1",
              orgnizationId: null,
              areaId: null,
              officeName: "邮电大厦",
              personCatId: "2",
              staffCode: "14612233356",
              managerId: "MP004",
              mobileNo: "13955842145",
              hasFace: null
            }
          ]
        },
        {
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          current: null,
          size: null,
          keyword: null,
          organizationId: "1449934343140081665",
          organizationName: "研发部门-B",
          parentOrganizationId: "1449933941678080001",
          allId: "1449933525389213697,1449933941678080001,1449934343140081665",
          mainDataId: "10003",
          officeAreaId: "1443123133698580481",
          deleted: null,
          remark: null,
          personTreeList: [
            {
              createBy: null,
              createTime: null,
              updateBy: null,
              updateTime: null,
              current: null,
              size: null,
              keyword: null,
              personId: "1446313228400328705",
              personName: "刘命",
              sex: "1",
              orgnizationId: null,
              areaId: null,
              officeName: "邮电大厦",
              personCatId: "2",
              staffCode: "A1003",
              managerId: "MP004",
              mobileNo: "18856889968",
              hasFace: null
            }
          ]
        },
        {
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          current: null,
          size: null,
          keyword: null,
          organizationId: "1449934722061893634",
          organizationName: "需求部门-A",
          parentOrganizationId: "1449933525389213697",
          allId: "1449933525389213697,1449934722061893634",
          mainDataId: "20002",
          officeAreaId: "1443123133698580481",
          deleted: null,
          remark: null,
          personTreeList: [
            {
              createBy: null,
              createTime: null,
              updateBy: null,
              updateTime: null,
              current: null,
              size: null,
              keyword: null,
              personId: "1447381634205630466",
              personName: "李时",
              sex: "1",
              orgnizationId: null,
              areaId: null,
              officeName: "邮电大厦",
              personCatId: "2",
              staffCode: "A1004",
              managerId: "MP004",
              mobileNo: "18856889968",
              hasFace: null
            }
          ]
        },
        {
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          current: null,
          size: null,
          keyword: null,
          organizationId: "1449933525389213697",
          organizationName: "省DICT",
          parentOrganizationId: "0",
          allId: "1449933525389213697",
          mainDataId: "10000",
          officeAreaId: "1443123133698580481",
          deleted: null,
          remark: null,
          personTreeList: [
            {
              createBy: null,
              createTime: null,
              updateBy: null,
              updateTime: null,
              current: null,
              size: null,
              keyword: null,
              personId: "1451437182068752386",
              personName: "王二麻",
              sex: "2",
              orgnizationId: null,
              areaId: null,
              officeName: "办公室一",
              personCatId: "3",
              staffCode: "88880001",
              managerId: "MP001",
              mobileNo: "18855660001",
              hasFace: null
            },
            {
              createBy: null,
              createTime: null,
              updateBy: null,
              updateTime: null,
              current: null,
              size: null,
              keyword: null,
              personId: "1451439068645806082",
              personName: "李嬷嬷",
              sex: "1",
              orgnizationId: null,
              areaId: null,
              officeName: "办公室二",
              personCatId: "3",
              staffCode: "88880003",
              managerId: "MP004",
              mobileNo: "18855660008",
              hasFace: null
            },
            {
              createBy: null,
              createTime: null,
              updateBy: null,
              updateTime: null,
              current: null,
              size: null,
              keyword: null,
              personId: "1452549056927711233",
              personName: "张四",
              sex: "1",
              orgnizationId: null,
              areaId: null,
              officeName: "邮电大厦",
              personCatId: "3",
              staffCode: "A1009",
              managerId: "10001",
              mobileNo: "18856892222",
              hasFace: null
            }
          ]
        },
        {
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          current: null,
          size: null,
          keyword: null,
          organizationId: "1449933941678080001",
          organizationName: "研发部门",
          parentOrganizationId: "1449933525389213697",
          allId: "1449933525389213697,1449933941678080001",
          mainDataId: "10001",
          officeAreaId: "1443123133698580481",
          deleted: null,
          remark: null,
          personTreeList: [
            {
              createBy: null,
              createTime: null,
              updateBy: null,
              updateTime: null,
              current: null,
              size: null,
              keyword: null,
              personId: "1451437762388459522",
              personName: "张飞",
              sex: "2",
              orgnizationId: null,
              areaId: null,
              officeName: "办公室二",
              personCatId: "2",
              staffCode: "88880002",
              managerId: "MP002",
              mobileNo: "18855660002",
              hasFace: null
            }
          ]
        },
        {
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          current: null,
          size: null,
          keyword: null,
          organizationId: "1449934375377502209",
          organizationName: "研发部门-C",
          parentOrganizationId: "1449933941678080001",
          allId: "1449933525389213697,1449933941678080001,1449934375377502209",
          mainDataId: "10004",
          officeAreaId: "1443123133698580481",
          deleted: null,
          remark: null,
          personTreeList: [
            {
              createBy: null,
              createTime: null,
              updateBy: null,
              updateTime: null,
              current: null,
              size: null,
              keyword: null,
              personId: "1452549056810270722",
              personName: "liuxx123445",
              sex: "2",
              orgnizationId: null,
              areaId: null,
              officeName: "1611",
              personCatId: "2",
              staffCode: "12345",
              managerId: "MP005",
              mobileNo: "17755101903",
              hasFace: null
            }
          ]
        },
        {
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          current: null,
          size: null,
          keyword: null,
          organizationId: "1451016732872298498",
          organizationName: "拓展部",
          parentOrganizationId: "1449934343140081665",
          allId:
            "1449933525389213697,1449933941678080001,1449934343140081665,1451016732872298498,1451016732872298498",
          mainDataId: null,
          officeAreaId: "1450656061898993666",
          deleted: null,
          remark: null,
          personTreeList: [
            {
              createBy: null,
              createTime: null,
              updateBy: null,
              updateTime: null,
              current: null,
              size: null,
              keyword: null,
              personId: "1467776251849101313",
              personName: "lin",
              sex: "1",
              orgnizationId: null,
              areaId: null,
              officeName: "安徽省庐阳区邮电大厦",
              personCatId: "3",
              staffCode: null,
              managerId: "MP005",
              mobileNo: "18756907782",
              hasFace: null
            }
          ]
        }
      ]
    };
    //this.treeData=dataData.data
    this.treeData =
      JSON.parse(JSON.stringify(this.formatData(dataData.data))) || [];

    let ontherData = {
      code: 200,
      msg: "处理成功",
      time: 1638949679530,
      success: true,
      data: [
        {
          id: "1443123111993057282",
          allId: "1443123111993057282",
          parentAreaId: "0",
          areaLevel: null,
          areaName: "安徽省",
          deviceList: [],
          children: [
            {
              id: "1443123122847916033",
              allId: "1443123111993057282,1443123122847916033",
              parentAreaId: "1443123111993057282",
              areaLevel: null,
              areaName: "合肥市",
              deviceList: [
                { deviceId: "1465150150668611585", deviceName: "宇视测试机器" },
                {
                  deviceId: "0109000005",
                  deviceName: "3F_01#动力机房_01#信昆_信昆门禁(五里墩3F 动力)"
                },
                {
                  deviceId: "0109000004",
                  deviceName: "5F_01#数据机房_01#信昆_信昆门禁(钟楼5F数据)"
                }
              ],
              children: [
                {
                  id: "1443123127612645378",
                  allId:
                    "1443123111993057282,1443123122847916033,1443123127612645378",
                  parentAreaId: "1443123122847916033",
                  areaLevel: null,
                  areaName: "庐阳区",
                  deviceList: [],
                  children: [
                    {
                      id: "1443123131412684802",
                      allId:
                        "1443123111993057282,1443123122847916033,1443123127612645378,1443123131412684802",
                      parentAreaId: "1443123127612645378",
                      areaLevel: null,
                      areaName: "邮电大厦",
                      deviceList: [],
                      children: [
                        {
                          id: "1443123133698580481",
                          allId:
                            "1443123111993057282,1443123122847916033,1443123127612645378,1443123131412684802,1443123133698580481",
                          parentAreaId: "1443123131412684802",
                          areaLevel: null,
                          areaName: "研发中心",
                          deviceList: [
                            {
                              deviceId: "1466319215743508481",
                              deviceName:
                                "5F_01#数据机房_01#信昆_信昆门禁(钟楼5F数据 llm)"
                            }
                          ],
                          children: null
                        }
                      ]
                    }
                  ]
                },
                {
                  id: "1450656357668728833",
                  allId:
                    "1443123111993057282,1443123122847916033,1450656357668728833",
                  parentAreaId: "1443123122847916033",
                  areaLevel: null,
                  areaName: "蜀山区",
                  deviceList: [
                    {
                      deviceId: "0109000008",
                      deviceName: "4F_01#MODF机房_01#信昆_信昆门禁(1)"
                    }
                  ],
                  children: null
                }
              ]
            },
            {
              id: "1447740218563198977",
              allId: "1443123111993057282,1447740218563198977",
              parentAreaId: "1443123111993057282",
              areaLevel: null,
              areaName: "安庆市",
              deviceList: [],
              children: [
                {
                  id: "1447740603617083394",
                  allId:
                    "1443123111993057282,1447740218563198977,1447740603617083394",
                  parentAreaId: "1447740218563198977",
                  areaLevel: null,
                  areaName: "迎江区",
                  deviceList: [],
                  children: null
                }
              ]
            },
            {
              id: "1450633686880915458",
              allId: "1443123111993057282,1450633686880915458",
              parentAreaId: "1443123111993057282",
              areaLevel: null,
              areaName: "六安市",
              deviceList: [],
              children: [
                {
                  id: "1450634906630656001",
                  allId:
                    "1443123111993057282,1450633686880915458,1450634906630656001",
                  parentAreaId: "1450633686880915458",
                  areaLevel: null,
                  areaName: "霍邱县",
                  deviceList: [],
                  children: null
                },
                {
                  id: "1450636848480161793",
                  allId: "1443123111993057282,1450633686880915458",
                  parentAreaId: "1450633686880915458",
                  areaLevel: null,
                  areaName: "霍邱县",
                  deviceList: [],
                  children: null
                },
                {
                  id: "1450652335113089025",
                  allId:
                    "1443123111993057282,1450633686880915458,1450652335113089025",
                  parentAreaId: "1450633686880915458",
                  areaLevel: null,
                  areaName: "霍邱县",
                  deviceList: [],
                  children: null
                },
                {
                  id: "1450656061898993666",
                  allId:
                    "1443123111993057282,1450633686880915458,1450656061898993666",
                  parentAreaId: "1450633686880915458",
                  areaLevel: null,
                  areaName: "舒城县",
                  deviceList: [],
                  children: null
                }
              ]
            },
            {
              id: "1450634599381110785",
              allId: "1443123111993057282,1450634599381110785",
              parentAreaId: "1443123111993057282",
              areaLevel: null,
              areaName: "马鞍山",
              deviceList: [],
              children: [
                {
                  id: "1455437009659539458",
                  allId:
                    "1443123111993057282,1450634599381110785,1455437009659539458",
                  parentAreaId: "1450634599381110785",
                  areaLevel: null,
                  areaName: "A区",
                  deviceList: [],
                  children: null
                },
                {
                  id: "1455437108674473986",
                  allId:
                    "1443123111993057282,1450634599381110785,1455437108674473986",
                  parentAreaId: "1450634599381110785",
                  areaLevel: null,
                  areaName: "B区",
                  deviceList: [],
                  children: null
                }
              ]
            }
          ]
        }
      ]
    };



   
    //获取值
    let changeData=ontherData.data[0].children
    console.log(changeData)

     this.twoChangData(changeData)
     console.log(this.quanxianData)

  },
  mounted() {},
  methods: {
    twoChangData(changeData){
         changeData.forEach((item)=>{
            this.recursionChildren(item.children)
            this.recursiondeviceList(item.deviceList)
         })
    },

    recursionChildren(dataData){
        if(dataData.length>0){
            dataData.forEach((item)=>{
                  //this.recursionChildren(item.children)
                  this.recursiondeviceList(item.deviceList)
            })
        }
        
    },
    recursiondeviceList(dataChange){
        if(dataChange.length>0){
            dataChange.forEach((item)=>{
                 this.quanxianData.push({
                       deviceId: item.deviceId,
                       deviceName:item.deviceName
                 })
            })
        }
    },
    formatData(data) {
      const that = this;
      data.forEach(element => {
        if (!element.organizationId) {
          element.organizationId = element.personId;
          element.organizationName = element.personName;
        }
        if (element.personTreeList && element.personTreeList.length > 0) {
          that.formatData(element.personTreeList);
        } else {
          element.personTreeList = undefined;
        }
      });
      return data;
    },
    onExpand(expandedKeys) {
      console.log("onExpand", expandedKeys);
      // if not set autoExpandParent to false, if children expanded, parent can not collapse.
      // or, you can remove all expanded children keys.
      this.expandedKeys = expandedKeys;
      this.autoExpandParent = false;
    },
    onCheck(checkedKeys) {
      console.log("onCheck  zzzzz", checkedKeys);
      this.checkedKeys = checkedKeys;
    },
    onSelect(selectedKeys, info) {
      console.log("onSelect", info);
      this.selectedKeys = selectedKeys;
    }
  }
};
</script>

<style lang="scss" scoped>
.chart-container {
  position: relative;
  width: 100%;
  height: calc(100vh - 84px);
}
</style>
